from django.db import models

from cars.models import Car
from teacher.models import TeacherModel


class Security(models.Model):
    LEVEL_CHOISE = (
        (0, "正常"),
        (1, "提级"),
        (2, "关闭"),
    )
    level = models.IntegerField("安全等级", choices=LEVEL_CHOISE, default=0)
    describe = models.CharField("描述", max_length=512, null=True, blank=True)
    creater = models.CharField("修改人", max_length=128, default="系统")
    created = models.DateTimeField("创建时间", auto_now_add=True, null=True, blank=True)
    updated = models.DateTimeField("更新时间", auto_now=True, null=True, blank=True)

    def __str__(self):
        return f"安全等级"

    class Meta:
        verbose_name = verbose_name_plural = "安全等级"


class Batch(models.Model):
    title = models.CharField("主题", max_length=50)
    isfree = models.IntegerField("是否免停车费", default=0)
    startdate = models.DateField("开始日期")
    enddate = models.DateField("结束日期")
    creater = models.ForeignKey(
        TeacherModel, on_delete=models.CASCADE, verbose_name="创建者"
    )
    created = models.DateTimeField("创建时间", auto_now_add=True, null=True, blank=True)
    updated = models.DateTimeField("更新时间", auto_now=True, null=True, blank=True)

    def __str__(self):
        return f"批量预约-{self.title}"

    class Meta:
        verbose_name = verbose_name_plural = "批量预约"


class BatchCar(models.Model):
    batch = models.ForeignKey(Batch, on_delete=models.CASCADE, verbose_name="批量预约")
    car = models.ForeignKey(Car, on_delete=models.CASCADE, verbose_name="车辆")
    creater = models.ForeignKey(
        TeacherModel, on_delete=models.CASCADE, verbose_name="创建者"
    )
    created = models.DateTimeField("创建时间", auto_now_add=True, null=True, blank=True)
    updated = models.DateTimeField("更新时间", auto_now=True, null=True, blank=True)

    def __str__(self):
        return f"批量预约车辆-{self.batch.title}"

    class Meta:
        verbose_name = verbose_name_plural = "批量预约-车辆"
